package com.globaldom.model;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

//@Configurable
@PersistenceCapable
public class MilResource implements Serializable {

	@NotPersistent
	private static final long serialVersionUID = 1L;

	@PrimaryKey
	private String id;

	@Persistent
	private String person;

	@NotPersistent
	public static final transient Integer ARMY = 0;
	@NotPersistent
	public static final transient Integer TANK = 1;
	@NotPersistent
	public static final transient Integer AIR = 2;
	@NotPersistent
	public static final transient Integer NAVY = 3;
	@NotPersistent
	public static final transient Integer SPIES = 4;
	@NotPersistent
	public static final transient Integer SUB = 5;

	// Number of units
	@Persistent
	private Long MilAvailable;
	// PoIntegerer to unit type
	@Persistent
	private Integer unitType;
	// last upgraded time
	@Persistent
	private Date resourceUpdated = new Date();
	@Persistent
	private Integer attackPoint = 1;
	@Persistent
	private Integer defendPoint = 5;

	public Long getMilAvailable() {
		return this.MilAvailable;
	}

	public void setMilAvailable(Long MilAvailable) {
		this.MilAvailable = MilAvailable;
	}

	public Integer getUnitType() {
		return this.unitType;
	}

	public void setUnitType(Integer unitType) {
		this.unitType = unitType;
		this.attackPoint = (int) Math.round((3.5) * (unitType + 1));
		this.defendPoint = (int) Math.round((5.5) * (unitType + 1));
	}

	public Date getResourceUpdated() {
		return this.resourceUpdated;
	}

	public void setResourceUpdated(Date resourceUpdated) {
		this.resourceUpdated = resourceUpdated;
	}

	public String getPerson() {
		return this.person;
	}

	public void setPerson(String person) {
		this.person = person;
	}

	public Integer getAttackPoint() {
		return attackPoint;
	}

	public void setAttackPoint(Integer attackPoint) {
		this.attackPoint = attackPoint;
	}

	public Integer getDefendPoint() {
		return defendPoint;
	}

	public void setDefendPoint(Integer defendPoint) {
		this.defendPoint = defendPoint;
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Override
	public int hashCode() {
		return toString().hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof MilResource)) {
			return false;
		}
		MilResource mil = (MilResource) obj;
		return (getPerson().equals(mil.getPerson()) && getUnitType().equals(mil.getUnitType()));
	}

	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Id: ").append(getId()).append(", ");
		sb.append("MilAvailable: ").append(getMilAvailable()).append(", ");
		sb.append("UnitType: ").append(getUnitType()).append(", ");
		sb.append("ResourceUpdated: ").append(getResourceUpdated()).append(", ");
		sb.append("PersonID: ").append(getPerson());
		return sb.toString();
	}

}
